<template>
  <OA ref="oa" :key="new Date() +id" class="oa-container" :formId="id" @onSuccess="onSuccess" />
</template>

<script>
import OA, { Engine, injectRequest } from '@/components/oa/oa-process.umd'
import { post, get, put } from '@/api/request'
import '@/components/oa/oa-process.css'
import events from '@/events'
export default {
  components: {
    Engine,
    OA,
  },
  inject: ['closeCurrent'],
  data() {
    return {
      flag: 0,
    }
  },
  created() {
    injectRequest({ post, get, put })
    window.test = this
    // this.clear()
  },
  computed: {
    id() {
      return this.$route.query.id
    },
  },
  mounted() {
    events.$on('add-oa', this.clear)
  },
  destroyed() {
    events.$off('add-oa', this.clear)
  },
  methods: {
    onSuccess(v, mes) {
      if (v === '成功') {
        setTimeout(() => {
          this.$router.push({ path: '/process/approval/template' })
        },10)
        this.closeCurrent()
      } else {
         this.$message.error(mes)
      }
    },
    clear() {
      console.log('清空')
      try {
        this.$refs.oa.$refs.info.resetForm()
      } catch (e) {
        //
      }
    },
  },
}
</script>

<style >
.oa-container {
  background: #fff;
}
.layout .header .user-wrapper,
.layout .top-nav-header-index .user-wrapper {
  float: right;
  height: 100%;
  display: flex;
  align-items: center;
}
.layout .header .user-wrapper .action.action-full,
.layout .top-nav-header-index .user-wrapper .action.action-full {
  height: 100%;
  display: flex;
  align-items: center;
}
.engine {
  /* min-height: 100vh; */
  /* padding: 24px;
  overflow: auto; */
}
</style>